package com.mallcloud.mall.mall.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.common.excel.annotation.ResponseExcel;
import com.mallcloud.mall.mall.api.entity.MallAdvertisingModel;
import com.mallcloud.mall.mall.service.MallAdvertisingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "mall-广告")
@RestController
@RequiredArgsConstructor
@RequestMapping("/mall/advertising")
public class MallAdvertisingController {
    private final MallAdvertisingService sysAdvertisingService;

    @ApiOperation("分页")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('mall_advertising_view')")
    public R<IPage<MallAdvertisingModel>> page(Page page, MallAdvertisingModel sysAdvertising) {
        return R.ok(sysAdvertisingService.page(page, Wrappers.query(sysAdvertising)));
    }

    @ApiOperation("查询详情")
    @GetMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('mall_advertising_view')")
    public R<MallAdvertisingModel> getById(@PathVariable("id") Long id) {
        return R.ok(sysAdvertisingService.getById(id));
    }

    @ApiOperation("新增")
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('mall_advertising_add')")
    public R<Boolean> save(@RequestBody MallAdvertisingModel sysAdvertising) {
        return R.ok(sysAdvertisingService.saveAdvertising(sysAdvertising));
    }
	
    @ApiOperation("修改")
	@PostMapping("/update")
    @PreAuthorize("@pms.hasPermission('mall_advertising_edit')")
    public R<Boolean> updateById(@RequestBody MallAdvertisingModel sysAdvertising) {
        return R.ok(sysAdvertisingService.updateAdvertising(sysAdvertising));
    }

    @ApiOperation("批量删除")
	@DeleteMapping
    @PreAuthorize("@pms.hasPermission('mall_advertising_del')")
    public R<Boolean> removeByIds(@RequestBody List<Long> ids) {
        return R.ok(sysAdvertisingService.removeAdvertisingByIds(ids));
    }

	@ApiOperation("导出")
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('mall_advertising_export')")
    public List<MallAdvertisingModel> export(MallAdvertisingModel sysAdvertising) {
        return sysAdvertisingService.list(Wrappers.query(sysAdvertising));
    }
}
